var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/TreeSelect/hooks/useRequestOptions.ts
var useRequestOptions_exports = {};
__export(useRequestOptions_exports, {
  default: () => useRequestOptions
});
module.exports = __toCommonJS(useRequestOptions_exports);
var import_hooks = require("@szzj/hooks");
var import_react = require("react");
function useRequestOptions(optionsOrRequest) {
  const [treeData, setTreeData] = (0, import_react.useState)(
    Array.isArray(optionsOrRequest) ? optionsOrRequest : []
  );
  const clearOptions = (0, import_react.useCallback)(() => {
    setTreeData([]);
  }, []);
  const fetchOptions = (0, import_react.useCallback)(
    (keywords) => {
      if (typeof optionsOrRequest === "function") {
        return optionsOrRequest(keywords).then((data) => {
          setTreeData(data);
        });
      }
    },
    [optionsOrRequest]
  );
  const { execute: queryTreeData, cancel: cancelQuery } = (0, import_hooks.useDebounce)(fetchOptions);
  (0, import_react.useEffect)(() => {
    if (typeof optionsOrRequest === "function") {
      queryTreeData();
    } else if (Array.isArray(optionsOrRequest)) {
      setTreeData(optionsOrRequest);
    }
  }, [optionsOrRequest]);
  (0, import_react.useEffect)(() => {
    return () => {
      cancelQuery();
    };
  }, []);
  return {
    treeData,
    setTreeData,
    clearOptions,
    queryTreeData,
    cancelQuery
  };
}
